import os
import urllib

from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp                                        
import os
from google.appengine.api import users
from utilities import *
from entities import * 

from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import login_required


def Add(appSource,version):
    appCheck = Entities.Source.all()
    if appCheck.count() == 0:
        source = Entities.Source(StoreSource = appSource,Version = version)
        source.put()
   
    else:
        for app in appCheck:
            appID = app.key().id()
            aSource = Entities.Source.get_by_id(appID)
            aSource.StoreSource = appSource
            aSource.Version = version
            aSource.put()
    return 1
    
    
def Get():
    source_list = []
    sources = Entities.Source.all()
    for source in sources:
        source_dict = {}
        source_dict["id"] = source.key().id()
        source_dict["Version"] = source.Version
        source_dict["StoreSource"] = source.StoreSource.key()
        source_list.append(source_dict)
    tuple_source = tuple(source_list)
    return tuple_source

    
    
    